Developer Documentation

QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Color Spaces

A color space specifies how color information is represented. It defines a one-, two-, three-, or four-dimensional space whose dimensions, or components, represent intensity values. For example, RGB space is a three-dimensional color space whose components are the red, green, and blue intensities that make up a given color. Visually, these spaces are often represented by various solid shapes, such as cubes, cones, or polyhedra.

QuickDraw GX directly supports 28 different color spaces, to give you the convenience of working in whatever kinds of color data most suits your needs. The QuickDraw GX color spaces fall into several groups, or base families. They are

All color spaces within a base family differ only in details of storage format or else are related to each other by very simple mathematical formulas.

Within a base family, some of the differences among color spaces relate to their packing, the number of bits used to store each color component. For example, RGB colors might be stored with 5, 8, or 16 bits per component. Each storage format is a different color space. Internally, QuickDraw GX always converts colors so that each component has 16 bits; thus you can think of the 16-bit-per-component color spaces as the fundamental ones in each base family, and those with smaller storage spaces as packed (storage-compressed) versions.

Some QuickDraw GX color spaces have an alpha channel, an additional component that measures opacity or transparency. Alpha channels are described in the section "Color Spaces With Alpha Channels" .

The gxColorSpaces enumeration lists the color spaces directly supported by QuickDraw GX. Each color space has its own format for representing color information. The rest of this section discusses those color spaces and their formats.

Luminance-Based Color Spaces

Luminance is a scale of lightness. Luminance-based color spaces, or gray spaces, typically have a single component, ranging from black to white, as shown in Figure 26 . Luminance-based color spaces are used for black-and white and grayscale display and printing.

Figure 26 Luminance color space

A color is converted into luminance by evaluating its overall lightness. The luminance of a color expressed in RGB (see "RGB-Based Color Spaces" ), for example, can be calculated approximately with this formula:

luminance = 0.30 * red + 0.59 * green + 0.11 * blue;

The luminance-based color spaces supported by QuickDraw GX (and defined in the gxColorSpaces enumeration) are gxGraySpace and gxGrayASpace . The A in gxGrayASpace stands for a second component called an alpha channel; see the section "Color Spaces With Alpha Channels" for more information.

Table 3 describes details of the storage formats for gxGraySpace and gxGrayASpace . In each of these spaces, the luminance is specified by a single number whose range varies from 0 to 65,535. The color black has a luminance value of 0, regardless of the color space.

Table 3 Luminance-based color spaces supported by QuickDraw GX

Constant

Enumeration
Value

Explanation

gxGraySpace
0x000A 16 bits per component (gray only); component values range from 0 to 0xFFFF. Total storage size for each color value: 16 bits.
gxGrayASpace
0x008A 16 bits per component (gray and alpha); component values range from 0 to 0xFFFF. Total storage size for each color value: 32 bits. Alpha channels are described on "Color Spaces With Alpha Channels" .

Figure 27 is a visual representation of the storage formats for the luminance-based color spaces.

Note
This figure and all subsequent storage-format figures in this chapter assume that data storage is "big-endian," that is, that lower addresses correspond to higher-order bytes in a word or long word value. For processors whose storage model is different, the elements of the figures would be in a different order. These figures are presented for illustrative purposes only, and are not intended to specify details of storage order.

Figure 27 Storage formats for luminance-based color spaces

RGB-Based Color Spaces

RGB-based color spaces are the most commonly used color spaces in computer graphics, primarily because they are directly supported by most color monitors. The groups of color spaces within the RGB base family include

RGB Spaces

Any color expressed in RGB space is some mixture of three primary colors red, green, and blue. Most RGB-based color spaces can be visualized as a cube, as in Figure 28 , with corners of black, the three primaries (red, green, and blue), the three secondaries (cyan, magenta, and yellow), and white.

Figure 28 RGB color space

The RGB color spaces supported by QuickDraw GX (and defined in the gxColorSpaces enumeration) are gxRGBSpace , gxRGB16Space , gxRGB32Space , gxRGBASpace , and gxARGB32Space . See Table 4 and Figure 29 for storage-format details. In each of these spaces, a color value is represented by three or four color components, representing red, green, blue (and in some cases alpha); each component can vary in the number of bits used for its storage. The color black is represented by component values of 0 in the red, green, and blue components.

Table 4 RGB color spaces supported by QuickDraw GX

Constant

Enumeration
Value

Explanation

gxRGBSpace
0x0001 16 bits per component (red, green, and blue); component values range from 0 to 0xFFFF. Total storage size for each color value: 48 bits.
gxRGB16Space
0x0501 5 bits per component (red, green, and blue); component values range from 0 to 0x1F. Total storage size for each color value: 16 bits (bit 15 is not used).
gxRGB32Space
0x0801 8 bits per component (red, green, and blue); component values range from 0 to 0xFF. Total storage size for each color value: 32 bits (bits 24-31 are not used).
gxARGB32Space
0x1881 8 bits per component (red, green, blue, and alpha); component values range from 0 to 0xFF. Total storage size for each color value: 32 bits. Alpha channels are described on "Color Spaces With Alpha Channels" .
gxRGBASpace
0x0081 16 bits per component (red, green, blue, and alpha); component values range from 0 to 0xFFFF. Total storage size for each color value: 64 bits. Alpha channels are described on "Color Spaces With Alpha Channels" .

Figure 29 Storage formats for RGB color spaces

HSV and HLS Color Spaces

HSV space and HLS space are transformations of RGB space that allow colors to be described in terms more natural to an artist. The name HSV stands for hue, saturation, and value, and HLS stands for hue, lightness, and saturation. The two spaces can be thought of as being single and double cones, as shown in Figure 30 .

Figure 30 HSV color space and HLS color space

The components in HLS space are analogous, but not completely identical, to the components in HSV space:

The HLS and HSV color spaces supported by QuickDraw GX (and defined in the gxColorSpaces enumeration) are gxHSVSpace , gxHLSSpace , gxHSV32Space , and gxHLS32Space . See Table 5 and Figure 31 for details of storage format.

Table 5 HSV and HLS color spaces supported by QuickDraw GX

Constant

Enumeration
Value

Explanation

gxHSVSpace
0x0003 16 bits per component (hue, saturation, and value); component values range from 0 to 0xFFFF. Total storage size for each color value: 48 bits.
gxHLSSpace
0x0004 16 bits per component (hue, lightness, and saturation); component values range from 0 to 0xFFFF. Total storage size for each color value: 48 bits.
gxHSV32Space
0x0A03 10 bits per component (hue, saturation, and value); component values range from 0 to 0x3FF. Total storage size for each color value: 32 bits (bits 30-31 are not used).
gxHLS32Space
0x0A04 10 bits per component (hue, lightness, and saturation); component values range from 0 to 0x3FF. Total storage size for each color value: 32 bits (bits 30-31 are not used).

Figure 31 shows storage formats for the supported HSV color spaces. Formats for the HLS spaces are identical.

Figure 31 Storage formats for HSV color spaces

CMYK Color Spaces

CMYK space is a color space that models the way ink builds up in printing. The name CMYK refers to cyan, magenta, yellow, and black. Cyan, magenta, and yellow are the three primary colors in this color space, and red, green, and blue are the three secondaries. Theoretically black is not needed. However, when full-saturation cyan, magenta, and yellow inks are mixed equally on paper, the result is usually a dark brown, rather than black. Therefore, black ink is overprinted in darker areas to give a better appearance. Figure 32 shows how the primary colors in CMYK space mix to form other colors.

Figure 32 Colors in CMYK color space

Theoretically, the relation between RGB values and CMY values in CMYK space is quite simple:

Cyan        = 1.0 - red;
Magenta     = 1.0 - green;
Yellow      = 1.0 - blue;

(where red, green, and blue intensities are expressed as fractional values varying from 0 to 1). In reality, the process of deriving the cyan, magenta, yellow, and black values from a color expressed in RGB space is complex, involving device-specific, ink-specific, and even paper-specific calculations of the amount of black to add in dark areas ( black generation ), and the amount of other ink to remove ( undercolor removal ) where black is to be printed. The CMYK color spaces supported by QuickDraw GX (and defined in the gxColorSpaces enumeration) are gxCMYKSpace and gxCMYK32Space. See Table 6 and Figure 33 for details of storage format.

Table 6 CMYK color spaces supported by QuickDraw GX

Constant

Enumeration
Value

Explanation

gxCMYKSpace
0x0002 16 bits per component (cyan, magenta, yellow, and black); component values range from 0 to 0xFFFF. Total storage size for each color value: 64 bits.
gxCMYK32Space
0x0802 8 bits per component (cyan, magenta, yellow, and black); component values range from 0 to 0xFF. Total storage size for each color value: 64 bits.

Figure 33 Storage formats for CMYK color spaces

Universal Color Spaces

Some color spaces allow color to be expressed in a device-independent way. Whereas RGB colors vary with monitor characteristics, and CMYK colors vary with printer and paper characteristics, universal colors are meant to be true representations of colors as perceived by the human eye. These color representations, called universal color spaces, result from work carried out in 1931 by the Commission Internationale d'Eclairage (CIE), and for that reason are also called CIE-based color spaces.

In addition, broadcast-video color space (YIQ) is based on device-independent color characteristics, in that its colors are measured in terms of a standard device. It is therefore considered universal and is discussed in this section.

XYZ Space

There are several CIE-based color spaces, but all are derived from the fundamental XYZ space. The XYZ space allows colors to be expressed as a mixture of the three tristimulus values X, Y, and Z. The term tristimulus comes from the fact that color perception results from the retina of the eye responding to three types of stimuli. After experimentation, the CIE set up a hypothetical set of primaries, XYZ, that correspond to the way the eye's retina behaves.

The CIE defined the primaries so that all visible light maps into a positive mixture of X, Y, and Z, and so that Y correlates approximately to the apparent lightness of a color. Generally, the mixtures of X, Y, and Z components used to describe a color are expressed as percentages ranging from 0% up to, in some cases, just over 100%.

Other universal color spaces based on XYZ space are used primarily to relate some particular aspect of color or some perceptual color difference to XYZ values.

Yxy Space

Yxy space expresses the XYZ values in terms of x and y chromaticity coordinates, somewhat analogous to the hue and saturation coordinates of HSV space. The coordinates are shown in the following formulas, used to convert XYZ into Yxy:

Y = Y
x = X / (X+Y+Z)
y = Y / (X+Y+Z)

Note that the Z tristimulus value is incorporated into the new coordinates, and does not appear by itself. Since Y still correlates to the lightness of a color, the other aspects of the color are found in the chromaticity coordinates x and y. This allows color variation in Yxy space to be plotted on a two-dimensional diagram. Figure 34 shows the layout of colors in the x and y plane of Yxy space. Color Plate 4 at the front of this book shows the same plot in color.

Figure 34 Yxy chromaticities

L*u*v* Space and L*a*b* Space

One problem with representing colors using the XYZ and Yxy color spaces is that they are perceptually nonlinear: it is not possible to accurately evaluate the perceptual closeness of colors based on their relative positions in XYZ or Yxy space. Colors that are close together in Yxy space may seem very different to observers, and colors that seem very similar to observers may be widely separated in Yxy space.

L*u*v* space is a nonlinear transformation of XYZ space in order to create a perceptually linear color space. L*a*b* space is a nonlinear transformation (a third-order approximation) of the Munsell color-notation system (not described here). Both are designed to match perceived color difference with quantitative distance in color space.

Both L*u*v* space and L*a*b* space represent colors relative to a reference white point, which is a specific definition of what is considered white light, represented in terms of XYZ space, and usually based on the whitest light that can be generated by a given device. (In that sense L*u*v* and L*a*b* are not completely device independent; two numerically equal colors are truly identical only if they were measured relative to the same white point.)

A primary benefit of using L*u*v* space and L*a*b* space is that the perceived difference between any two colors is proportional to the geometric distance in the color space between their color values. For applications where closeness of color needs to be quantified, such as in colorimetry, gemstone evaluation, or dye matching, use of L*u*v* space or L*a*b* space is common.

The formulas for transforming an XYZ color into an L*u*v* color are

if (Y/Yn > 0.008856)
    L = 116.0 * (Y / Yn)1/3 - 16.0;
else
    L = 903.3 * (Y / Yn);
u = 13.0 * L * (u' - u'n);
v = 13.0 * L * (v' - v'n);

where

u' = 4 * x / (X + 15*Y + 3*Z);
v' = 9 * y / (X + 15*Y + 3*Z);

and u'n, v'n, and Yn are the u' , v' , and Y values for the reference white point.

Similarly, the formulas for transforming an XYZ color into an L*a*b* color are

if (Y/Yn > 0.008856)
    L = 116.0 * (Y / Yn)1/3 - 16.0;
else
    L = 903.3 * (Y / Yn)
a = 500.0 * ( (X / Xn)1/3 - (Y / Yn)1/3 );
b = 500.0 * ( (Y / Yn)1/3 - (Z / Zn)1/3 );

where Xn, Yn, and Zn are the XYZ values for the reference white point.

Formats for XYZ-Based Color Spaces

The universal color spaces supported by QuickDraw GX (and defined in the gxColorSpaces enumeration) are gxYXYSpace , gxXYZSpace , gxLUVSpace , gxLABSpace , gxYXY32Space , gxXYZ32Space , gxLUV32Space , and gxLAB32Space . See Table 7 and Figure 35 for details of storage format. Note that the ranges of values for the components differ significantly among the different color spaces.

Table 7 Universal color spaces supported by QuickDraw GX 

Constant

Enumeration
Value

Explanation

gxYXYSpace
0x0005 16 bits per component (Y, x, and y); component values range from 0 (0%) to 0xFFFF (100%). Total storage size for each color value: 48 bits.
gxXYZSpace
0x0006 16 bits per component (X, Y, and Z). Component values range from 0 (0%) to 0xFFFF (200%; a value of 0x8000 represents 100%). Total storage size for each color value: 48 bits.
gxLUVSpace
0x0007 16 bits per component (L*, u*, and v*). The L* component values range from 0 (0%) to 0xFFFF (100% of white-point luminance). The u* and v* component values range from 0 (-1) to 0xFFFF (+1). Total storage size for each color value: 48 bits.
gxLABSpace
0x0008 16 bits per component (L*, a*, and b*). The L* component values range from 0 (0%) to 0xFFFF (100% of white-point luminance). The a* and b* component values range from 0 (-1) to 0xFFFF (+1). Total storage size for each color value: 48 bits.
gxYXY32Space
0x0A05 10 bits per component (Y, x, and y); component values range from 0 (0%) to 0x3FF (100%). Total storage size for each color value: 32 bits (bits 30 and 31 not used).
gxXYZ32Space
0x0A06 10 bits per component (X, Y, and Z). Component values range from 0 (0%) to 0x3FF (200%; a value of 0x200 represents 100%). Total storage size for each color value: 32 bits (bits 30 and 31 not used).
gxLUV32Space
0x0A07 10 bits per component (L*, u*, and v*). The L* component values range from 0 (0%) to 0x3FF (100% of white-point luminance). The u* and v* component values range from 0 (-1) to 0x3FF (+1). Total storage size for each color value: 32 bits (bits 30 and 31 not used).
gxLAB32Space
0x0A08 10 bits per component (L*, a*, and b*). The L* component values range from 0 (0%) to 0x3FF (100% of white-point luminance). The a* and b* component values range from 0 (-1) to 0x3FF (+1). Total storage size for each color value: 32 bits (bits 30 and 31 not used).

Because u*, v*, a*, and b* are normally signed numbers between 1.0 and -1.0,
you can convert them into short integers as follows:
anUnsignedshort = ((aFloat + 1.0)/2) * 65535.0 ;

Figure 35 shows storage formats for the supported XYZ color spaces. Formats for the Yxy, L*u*v*, and L*a*b* spaces are identical.

Figure 35 Storage formats for XYZ color spaces

Video Color Spaces

YIQ space is sometimes called video color space. It is based on the way a specific kind of RGB data is broken down for color television transmission. The three dimensions that describe these color spaces are Y, I, and Q, in which Y represents luminance and the other two components carry color information.

Because the Y channel represents luminance it can be used alone; the Y channel is the only channel used in black and white television. The I and Q channels are called color difference channels: the Y channel is split between them. The notations "I" and "Q" stand for "in phase" and "in quadrature," respectively, referring to the method by which all of the channels are combined into a signal for broadcast.

QuickDraw GX also defines NTSC and PAL color spaces. NTSC space corresponds to the color encoding used for color broadcasting in the United States, whereas PAL space corresponds to the color encoding used in Europe. NTSC and PAL have different screen resolutions, frequencies, and are otherwise incompatible, but in terms of how color values are calculated, NTSC space and PAL space are both identical to YIQ space.

In YIQ space, the Y component can vary from 0 (black) to its maximum value (full luminance). I and Q are normally signed values, so they are centered around 0. Figure 36 illustrates how colors map into the I and Q dimensions of YIQ space.

Figure 36 The I and Q axes in YIQ color space

The video color spaces supported by QuickDraw GX (and defined in the gxColorSpaces enumeration) are gxYIQSpace , gxNTSCSpace , gxPALSpace , gxYIQ32Space , gxNTSC32Space , and gxPAL32Space . See Table 8 and Figure 37 for details of storage format. In each of these spaces, a color value is represented by Y, I, and Q color components.

Table 8 Video color spaces supported by QuickDraw GX

Constant

Enumeration
Value

Explanation

gxYIQSpace
0x0009 16 bits per component (Y, I, and Q); Y-component values range from 0 to 0xFFFF; I- and Q-component values range from -0x7FFF to +0x7FFF. Total storage size for each color value: 48 bits.
gxNTSCSpace
0x0009 (same as gxYIQSpace )
gxPALSpace
0x0009 (same as gxYIQSpace )
gxYIQ32Space
0x0A09 10 bits per component (Y, I, and Q); Y-component values range from 0 to 0x3FF; I- and Q-component values range from -0x1FF to +0x1FF. Total storage size for each color value: 32 bits (bits 30 and 31 are not used).
gxNTSC32Space
0x0A09 (same as gxYIQ32Space )
gxPAL32Space
0x0A09 (same as gxYIQ32Space )

Figure 37 shows storage formats for the supported YIQ color spaces. Formats for the NTSC and PAL spaces are identical.

Figure 37 Storage formats for YIQ color spaces

You can find more information on the theories of color and the various color spaces in the following publications:

Measuring Color, by R.W.G. Hunt, John Wiley & Sons, New York, 1987.

Illumination and Color in Computer Generated Imagery, by Roy Hall, Springer-Verlag, New York, 1989.

Color Spaces With Alpha Channels

QuickDraw GX supports the use of an alpha channel in one luminance-based color space ( gxGrayASpace ) and two RGB color spaces ( gxRGBASpace and gxARGB32Space ). An alpha channel is a component in a color space whose value typically determines the opacity of the color expressed by the other components. An alpha-channel value of 0 in a color means that the color is completely transparent, and a maximum value means that the color is completely opaque. A value in between means that the color is partially transparent.

How transparency is handled in drawing depends on the transfer mode used when the color is drawn. (Transfer modes are discussed in "Transfer Modes" .) Typically, however, transparency in a color being drawn--the source color-- means that the existing color at the location where drawing occurs--the destination color--shows through. Where the source is completely opaque, the destination is completely covered and is invisible; where the source is completely transparent, the destination shows through unchanged and the source is invisible.

Figure 38 shows an example in which a uniform gray image (in gxGrayASpace ) is drawn over a black-and-white image. The gray color of the source is uniform across the rectangle, but the alpha-channel value decreases from 0xFFFF on the left to 0 on the right. As the alpha value decreases rightward, more and more of the destination color shows through.

Figure 38 Showing color transparency with an alpha channel

Color-Component Values, Color Values, and Colors

Each of the color spaces described in this chapter requires one or more numeric values in a particular format to specify a color. This section describes the data types and structures with which QuickDraw GX describes colors in its color spaces.

Each dimension, or component, in a color space has a color-component value. In the fundamental, unpacked QuickDraw GX color spaces--those with 16 bits per component--each color-component value is of type gxColorValue :

typedef unsigned short gxColorValue;

A color-component value can vary from 0 to 65,535 (0xFFFF), although the numerical interpretation of that range is different for different color spaces. In most cases, color-component intensities are interpreted numerically as varying between 0 and 1.0; for that reason, QuickDraw GX provides the constant gxColorValue1 to represent 0xFFFF.

Depending on the color space used, one, two, three, or four color-component values combine to make a color value. A color value is a structure; it is the complete specification of a color in a given color space. QuickDraw GX supports 13 color-value formats, representing the fundamental 16-bits-per-component color spaces; all color operations in memory use one of those formats. The color-value formats are described in the section "Color-Component Values, Color Values, and Colors" . For example, an RGB color value has this format:

struct gxRGBColor{
    gxColorValue        red;
    gxColorValue        green;
    gxColorValue        blue;
};

This is exactly the storage format for colors in gxRGBSpace . However, colors stored in gxRGB16Space or gxRGB32Space have a packed storage format, and need to be converted to gxRGBColor format when they are used. QuickDraw GX takes care of this for you; as far as your application is concerned, you can always manipulate colors in the color space you have specified.

A color value plus a specification of the color space it belongs to constitute a color in QuickDraw GX. A color is defined by the gxColor structure:

struct gxColor{
    gxColorSpace                space;
    gxColorProfile              profile;
    union {
            struct gxCMYKColor              cmyk;
            struct gxRGBColor               rgb;
            struct gxRGBAColor              rgba;
            struct gxHSVColor               hsv;
            struct gxHLSColor               hls;
            struct gxXYZColor               xyz;
            struct gxYXYColor               yxy;
            struct gxLUVColor               luv;
            struct gxLABColor               lab;
            struct gxYIQColor               yiq;
            gxColorValue                    gray;
            struct gxGrayAColor             graya;
            unsigned short                  pixel16;
            unsigned long                   pixel32;
            struct gxIndexedColor           indexed;
            gxColorValue                    component[4];
    } element;
};

Each gxColor structure holds the specification of a single color. Note that, besides the basic color-value formats such as gxRGBColor and gxXYZColor , a QuickDraw GX color can contain a 16-bit or 32-bit pixel value, and you can also access the color as an array of color-component values. Each of the color values in the element union of the gxColor structure is described in the section "Color Structure" .


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |